<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>企业微信信息化平台</title>
    <link rel="stylesheet" th:href="@{/layui/css/layui.css}">
</head>
<body>

<script th:src="@{/layui/layui.js}"></script>

<script src="https://ajax.aspnetcdn.com/ajax/jQuery/jquery-3.6.0.js"></script>
<div class="search">
    <ul class="layui-nav" lay-filter="">
        <div class="layui-form-item">
            <form class="layui-form">
                <div class="layui-inline">
                    <label class="layui-form-label">人员名字</label>
                    <div class="layui-input-inline" style="width: 130px;">
                        <label>
                            <input type="text" name="engineer_name" placeholder="输入名字或部门" class="layui-input">
                        </label>
                    </div>
                    <label class="layui-form-label">群组名字</label>
                    <div class="layui-input-inline" style="width: 130px;">
                        <label>
                            <input type="text" name="group_name" placeholder="输入群名" class="layui-input">
                        </label>
                    </div>
                    <label class="layui-form-label">消息类型</label>
                    <div class="layui-input-inline" style="width: 130px;">
                        <input type="radio" name="type" value="problem" title="问题">
                        <input type="radio" name="type" value="message" title="信息" checked>
                    </div>
                    <label class="layui-form-label">是否处理</label>
                    <div class="layui-input-inline" style="width: 130px;">
                        <input type="radio" name="status" value="1" title="已经处理">
                        <input type="radio" name="status" value="0" title="未处理" checked>
                    </div>
                    <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                </div>
            </form>
        </div>
    </ul>

</div>
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 50px;">
    <legend>企业微信信息化</legend>
</fieldset>

<div class="layui-container">
    <div class="layui-row">
        <div class="layui-col-md2">
            <form class="layui-form">
                <label>
                    <select name="all_engineer" lay-verify="" lay-search lay-filter="formDemo" id="all_engineer">
                        <option value="all_engineer">全部员工</option>
                        <option th:each="engineer : ${all_engineer}" th:value="${engineer.getWx_engineer_id()}"
                                th:text="${engineer.getEngineer_name()}"></option>
                    </select>
                </label>
            </form>
            <div class="layui-panel">
                <ul class="layui-menu" id="docDemoMenu1">
                    <li lay-options="{type: 'message',status:1, engineer_id:'all_engineer'}">
                        <div class="layui-menu-body-title">已响应消息</div>
                    </li>
                    <li lay-options="{type:'problem',status:1, engineer_id:'all_engineer'}">
                        <div class="layui-menu-body-title">已处理问题</div>
                    </li>
                    <li lay-options="{type:'message',status:0, engineer_id:'all_engineer'}">
                        <div class="layui-menu-body-title">未响应消息</div>
                    </li>
                    <li lay-options="{type:'problem',status:0, engineer_id:'all_engineer'}">
                        <div class="layui-menu-body-title">未处理问题</div>
                    </li>
                </ul>
            </div>

        </div>
        <div class="layui-col-md5">
            <table class="layui-table">
                <colgroup>
                    <col width="550">
                </colgroup>
                <thead>
                <tr>
                    <th>群名</th>
                </tr>
                </thead>
                <tbody id="group_list">
                </tbody>
            </table>
        </div>
        <div class="layui-col-md4">


        </div>

    </div>

</div>

<script>

    let default_engineer = 'all_engineer'


    let group_list = document.getElementById("group_list")

    //ajax获取到的信息，先保存在这里
    let all_group_msg;

    let div_group_msg = "<tr>\n" +
        "                    <td><button type=\"button\" onclick=\"selMsgByGroup(id)\" class=\"layui-btn layui-btn-normal layui-btn-fluid\" id='cp_id'>cp_name</button></td>\n" +
        "                </tr>"
    onstart()
    //<option value="010">layer</option>
    layui.use('dropdown', function () {
        let dropdown = layui.dropdown;
        //菜单点击事件，其中 docDemoMenu1 对应的是菜单结构上的 id 指
        dropdown.on('click(docDemoMenu1)', function (options) {
            // const othis = $(this); //当前菜单列表的 DOM 对象
            options.engineer_id=default_engineer;
            // console.log(default_engineer)
            // options.add("engineer_id",default_engineer)
            console.log(options); //菜单列表的 lay-options 中的参数
        });
    });

    function selMsgByGroup(id) {
        console.log(id)
        $.ajax({
            url: "/msg_byGroupId"
            , data: {
                data: id
            }
            , type: "get"
            , dataType: "json"
            , contentType: "application/json;charset=utf-8"
            , success: function (data) {
                all_group_msg = data
                console.log(data)
            }
        })
    }

    function onstart() {
        let div_group_msg_temp;
        $.ajax({
            url: "/all_group"
            , type: "get"
            , dataType: "json"
            // , contentType: "application/json;charset=utf-8"
            , success: function (data) {
                for (let i = 0; i < data.length; i++) {

                    div_group_msg_temp = div_group_msg.replace("cp_name", data[i]["cpname"])
                    div_group_msg_temp = div_group_msg_temp.replace("cp_id", data[i]["cpid"])
                    group_list.innerHTML = group_list.innerHTML + div_group_msg_temp
                }
                console.log(data)
            }
        })

    }


    let question_list_head = document.getElementById("question_list_head")
    let question_list = document.getElementById("question_list")

    // {"engineer_name":"","group_name":"","type":"problem","status":"all"}

    layui.use('form', function () {
        var form = layui.form;
        form.on('select(formDemo)', function (data) {
            default_engineer = data.value
            console.log('选择的员工id' + default_engineer); //得到被选中的值
        });

        form.on('submit(formDemo)', function (data) {
            question_list.innerHTML = ""
            // layer.msg(JSON.stringify(data.field));
            let choose = data.field.type
            console.log(choose)
            $.ajax({
                url: "/msg_search"
                , data: {
                    data: JSON.stringify(data.field)
                }
                , type: "get"
                , dataType: "json"
                // , contentType: "application/json;charset=utf-8"
                , success: function (data) {


                    let row = "";
                    let head = "";
                    // head = "<tr>"
                    // // for (let key in data[0]) {
                    // //     head = head + "<th>" + key + "</th>"
                    // // }
                    // head = head + "</tr>"
                    // console.log(data[1])

                    question_list_head = head
                    // console.log(data.length + "data.length")
                    for (let i = 0; i < data.length; i++) {
                        console.log(data)

                        for (let key in data[i]) {
                            if (data[i][key] != null) {

                                row = row + "<td width='80'>" + data[i][key] + "</td>"
                                // console.log(key + "" + data[i][key])
                            }
                        }

                        row = "<tr>" + row + "</tr>"

                        // console.log(row + "end")
                    }
                    question_list.innerHTML = question_list.innerHTML + row
                    // console.log(data)
                    //      $("#question_list").html(obj.title);
                    // console.log(data)
                    // layer.msg(data);
                }
            })


            return false;
        });
    });

    // ajax()

    function ajax() {
        $.ajax({
            url: "/msg_all_need_reply"
            // , data: data.field
            , type: "get"
            , dataType: "json"
            // , contentType: "application/json;charset=utf-8"
            , success: function (data) {
                if (data.status === "200") {
                    layer.open({
                        title: '提示'
                        , content: "注册成功"
                    });
                } else if (data.status === "301") {
                    layer.open({
                        title: '提示'
                        , content: "用户名已存在"
                    });
                    return false;
                } else {
                    layer.open({
                        title: '提示'
                        , content: "请求错误，请联系管理员"
                    });
                    console.log(data)
                    return false;
                }
            }
        })
    }


    layui.use('dropdown', function () {
        const dropdown = layui.dropdown;
        dropdown.render({
            elem: '#demo1'
            , data: [{
                title: 'menu item 1'
            }, {
                title: 'menu item 2'
                , id: 101
            }]
            , id: 'demo1'
            //菜单被点击的事件
            , click: function (obj) {
                console.log(obj);
                $("#demo1").html(obj.title);

                layer.msg('回调返回的参数已显示再控制台');
            }
        });
    });

    //注意：导航 依赖 element 模块，否则无法进行功能性操作
    layui.use('element', function () {
        var element = layui.element;

        //…
    });
</script>


</body>
</html>